package com.liu.controller;

import com.liu.pojo.Emp;
import com.liu.pojo.Result;
import com.liu.utils.XmlParserUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    @RequestMapping("/listEmp")
    public Result list(){
        String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();
        System.out.println(file);
        List<Emp> empList = XmlParserUtils.parse(file, Emp.class);

        empList.stream().forEach(emp -> {
            String gender = emp.getGender();
            if (gender.equals("1")){
                emp.setGender("男");
            }else if (gender.equals("2")){
                emp.setGender("女");
            }

            String job = emp.getJob();
            if (job.equals("1")){
               emp.setJob("讲师");
            }else if (job.equals("2")){
                emp.setJob("班主任");
            } else if (job.equals("3")) {
                emp.setJob("就业指导");

            }
        });

            return Result.success(empList);
    }
}
